package com.bank.view;

import com.bank.javabean.Account;
import com.bank.service.AdminService;
import com.bank.serviceimpl.AdminServiceImpl;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @Auther: Liu
 */
public class AdminView {
    //跳转管理员页面  需要将当前登录账号信息传入
    public static void view(Account account) {
        AdminService adminService=new AdminServiceImpl();
        //当前账号id
        int myId=account.getId();
        Scanner scInt = new Scanner(System.in);
        Scanner scString = new Scanner(System.in);
        System.out.println("======管理员页面======");
        while (true) {
            System.out.println("请输入选择1-创建账号 2-销户 3-修改密码 4-查询信息 5-返回");
            int choose = scInt.nextInt();
            if(choose==1){
                System.out.println("请输入创建账号类型1-管理员 2-用户");
                int type=scInt.nextInt();
                System.out.println("请输入创建账号");
                String username = scString.nextLine();
                System.out.println("请输入账号密码");
                String password = scString.nextLine();
                System.out.println("请输入真实姓名");
                String name = scString.nextLine();
                System.out.println("请输入邮箱号码");
                String mail = scString.nextLine();
                System.out.println("请输入手机号码");
                String phone = scString.nextLine();
                //调用管理员服务注册方法
                if(type==1){
                    adminService.addAdmin(username,password,name,mail,phone);
                }else if(type==2){
                    adminService.addUser(username,password,name,mail,phone);
                }
            }else if(choose==2){
                System.out.println("请输入删除账号id(仅能删除非当期账号外的账号)");
                int id = scInt.nextInt();
                //调用管理员服务销户方法
                adminService.removeAccount(myId,id);
            }else if(choose==3){
                System.out.println("请输入修改账号id(管理员仅支持当前账号修改)");
                int id = scInt.nextInt();
                System.out.println("请输入修改密码");
                String password = scString.nextLine();
                //调用管理员服务修改密码方法
                adminService.restPassword(myId,id,password);
            }else if(choose==4){
                System.out.println("请输入查询账号类型1-管理员 2-用户");
                int type = scInt.nextInt();
                //调用管理员服务根据账号类型查询方法
                ArrayList<Account> list = adminService.findAccount(type);
                for (Account account1 : list) {
                    System.out.println(account1);
                }
            }else{
                break;
            }
        }

    }
}
